<template>
  <div>
    <el-dialog
      title="项目进度表"
      :close-on-click-modal="false"
      :visible.sync="visible"
    >
      <el-switch
        v-model="value1"
        active-text="已完成"
        inactive-text="未完成"
        @change="getList()"
      ></el-switch>
      <el-switch
        v-model="value2"
        active-text="有效"
        inactive-text="失效"
        @change="getList()"
      ></el-switch>
      <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
      <el-table :data="tableData" style="width: 100%" height="300">
        <el-table-column prop="project_content" label="分配内容">
        </el-table-column>
        <el-table-column prop="nick_name" label="负责人姓名"> </el-table-column>
        <el-table-column prop="progress_status" label="进度">
          <template slot-scope="scope">
            <span>{{ scope.row.progress_status }}%</span>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              v-if="isAuth('sys:role:update')"
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row)"
              >修改</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <task-update ref="taskUpdate" @refreshDataList="getList"></task-update>
  </div>
</template>

<script>
import taskUpdate from "./task-add-update.vue";
export default {
  components: {
    taskUpdate,
  },
  data() {
    return {
      id: "",
      visible: false,
      options: [],
      value1: false,
      value2: true,
      tableData: [],
    };
  },
  methods: {
    addOrUpdateHandle(val) {
      this.$nextTick(() => {
        this.$refs.taskUpdate.init(val, this.id);
      });
    },
    init(id) {
      this.id = id || 0;
      this.visible = true;
      this.getList(this.id);
    },
    getList() {
      this.$http({
        url: this.$http.adornUrl("/business/eprojectschedule/query"),
        method: "get",
        params: this.$http.adornParams({
          isFinish: this.value1 ? 1 : 0,
          projectId: this.id,
          flag: this.value2 ? 1 : 0,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.tableData = data.page.records;
        }
      });
    },
  },
};
</script>
